﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;

using BusinessLogic.BusinessRules;
using BusinessLogic.ClassFactory;
using Model;

namespace Util.PageInfo
{
    public class PageInfo
    {
        public static string ShowPagePath(int intSectionId)
        {
            StringBuilder strbuPagePath = new StringBuilder();
            List<string> listPagePath = new List<string>();
            FindEveryChildPath(ref listPagePath, intSectionId);

            if (listPagePath.Count > 0)
            {
                for (int i = listPagePath.Count; i > 0; i--)
                {
                    if (i != 1)
                    {
                        strbuPagePath.Append("><a href='###'>" + listPagePath[i - 1] + "</a>");
                    }
                    else
                    {
                        strbuPagePath.Append("><span style='color: #417DB7'>" + listPagePath[i - 1] + "</span>");
                    }
                }
            }
            return strbuPagePath.ToString();
        }

        /// <summary>
        /// 获取连接组名字
        /// </summary>
        /// <param name="intSectionId"></param>
        /// <returns></returns>
        public static string ShowLinkGroupName(int intLinkGroupID)
        {
            string groupname = "";
            using (LinksGroupFactory objLinksGroupFactory = new LinksGroupFactory())
            {
                BusinessLogic.BusinessRules.LinksGroup objLinksGroup = objLinksGroupFactory.Creator(intLinkGroupID);
                if (objLinksGroup != null)
                {
                    groupname = objLinksGroup.DataItem.chvGName;
                }
            }
            return groupname;
        }

        /// <summary>
        /// 查找页面各个父级
        /// </summary>
        /// <param name="listcontainor">容器</param>
        /// <param name="intSectionId">SectionID</param>
        private static void FindEveryChildPath(ref List<string> listcontainor, int intSectionId)
        {
            using (SectionsFactory objFactory = new SectionsFactory())
            {
                BusinessLogic.BusinessRules.Sections objSections = objFactory.Creator(intSectionId);
                if (objSections != null)
                {
                    listcontainor.Add(objSections.DataItem.chvSTCName);
                    if (objSections.DataItem.intParentID > 0)
                    {
                        FindEveryChildPath(ref listcontainor, objSections.DataItem.intParentID);
                    }
                }
            }
        }
    }
}